/*gBbkqi6GKNdhFHW+ynx98oUhyGnkP2MuqH/CI1rd3lYPnCBh0QTX83msehlKhd1G*/
/*
 * @Author: xiahui 
 * @PageInfo: 表体参照过滤
 * @Date: 2019-01-22 15:43:38 
 * @Last Modified by: zhr
 * @Last Modified time: 2021-09-08 22:44:53
 */
import { AREA, FIELDS } from '../../constance';

function bodyReferFilter(props, moduleId, key, value, index, record) {
	let meta = props.meta.getMeta();
	let item = meta[moduleId].items.find((item) => item.attrcode == key);

	let pk_org = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_org).value; // 主组织
	let pk_group = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.pk_group).value; // 集团

	if (FIELDS.pk_material == key) {
		// 物料
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_org: pk_org
					// SCM_DISCOUNTFLAG: 'N',
					// SCM_FEEFLAG: 'N',
					// GridRefActionExt: 'nccloud.web.scmpub.ref.MaterialRefFilterUtils'
				};
			}
		});
	} else if (FIELDS.ctranspmodeid == key || FIELDS.cproductorid == key || FIELDS.cproductorid == key) {
		// 运输方式|生产厂商|质量等级
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_group: pk_group
				};
			}
		});
	} else if (FIELDS.castunitid == key || FIELDS.cqtunitid == key) {
		// 单位 | 报价单位
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					scm_cmaterialid: record.values[FIELDS.pk_material].value,
					GridRefActionExt: 'nccloud.web.scmpub.ref.MeasdocRefFilterUtils'
				};
			}
		});
	} else if (FIELDS.cqpbaseschemeid == key) {
		// 优质优价方案
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_material: record.values[FIELDS.pk_material].value,
					pk_org: pk_org,
					pk_group: pk_group,
					GridRefActionExt: 'nccloud.web.ct.purdaily.ref.Z2CqpbaseschemeidRefSql'
				};
			}
		});
	} else if (FIELDS.ctaxcodeid == key) {
		// 税码
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				let ctaxcountryid = record.values[FIELDS.ctaxcountryid].value;
				let fbuysellflag = record.values[FIELDS.fbuysellflag].value;
				return {
					SCM_REPTAXCOUNTRY: ctaxcountryid,
					SCM_PURSALETYPE: fbuysellflag,
					GridRefActionExt: 'nccloud.web.scmpub.ref.TaxCodeRefFilterUtils'
				};
			}
		});
	} else if (FIELDS.pk_ct_price == key) {
		// 合同价格信息
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				let cvendorid = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.cvendorid).value; // 供应商
				let corigcurrencyid = props.form.getFormItemsValue(AREA.cardFormId, FIELDS.corigcurrencyid).value; // 原币币种
				return {
					pk_org: pk_org,
					cvendorid: cvendorid,
					corigcurrencyid: corigcurrencyid,
					pk_marbasclass: record.values[FIELDS.pk_marbasclass].value,
					pk_material: record.values[FIELDS.pk_srcmaterial].value, // 物料OID
					cqtunitid: record.values[FIELDS.cqtunitid].value,
					GridRefActionExt: 'nccloud.web.ct.purdaily.ref.Z2PriceInfoRefSql'
				};
			}
		});
	} else if (item.attrcode.indexOf('vfree') == 0) {
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_org: pk_org
				};
			}
		});
	} else if (item.attrcode.indexOf('vbdef') == 0) {
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_org: pk_org
				};
			}
		});
	} else if (item.attrcode == FIELDS.casscustid || item.attrcode == FIELDS.casscustvid) {
		// 客户--固定属性
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_org: pk_org
				};
			}
		});
	} else if (item.attrcode == FIELDS.cvendorid) {
		// 供应商--固定属性
		props.cardTable.setQueryCondition(moduleId, {
			[item.attrcode]: () => {
				return {
					pk_org: pk_org
				};
			}
		});
	}

	return meta;
}

export { bodyReferFilter };

/*gBbkqi6GKNdhFHW+ynx98oUhyGnkP2MuqH/CI1rd3lYPnCBh0QTX83msehlKhd1G*/